import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:wk_weather/bean/AppNavigatorObserver.dart';
import 'package:wk_weather/bean/MyRouter.dart';
import 'package:wk_weather/myConfig/weather_type.dart';
import 'package:wk_weather/utils/ImageUtils.dart';
import 'package:wk_weather/views/pages/home/HomePage.dart';
import 'dart:ui' as ui;

import 'package:flutter_weather_bg/utils/WeatherUtil.dart';

EventBus eventBus = EventBus();
GlobalKey globalKey = GlobalKey();
///  ValueNotifier 包含一个 value 值，
///  当值改变的时候，会通知它的监听者 用来同步滚动位置
ValueNotifier<double> offsetNotifier = ValueNotifier<double>(0);
Map<WeatherType, ui.Image> weatherImages = {};

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    _fetchWeatherImages();
    return MaterialApp(
      title: "Wk天气",  // 在Android上，在任务管理器的应用程序快照上面显示，在IOS上忽略此属性
      debugShowCheckedModeBanner: false, // 不显示右上角的 debug 标记
      onGenerateRoute: MyRouter.generateRoute ,  // 路由拦截器
      navigatorObservers: [AppNavigatorObserver()], // 导航监听
      color: Colors.blue[600],
      // AnnotatedRegion 可以用来改变状态栏颜色
      home: AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle.light,
        child: HomePage(key: globalKey),
      ),
    );
  }
}

void _fetchWeatherImages() async {
  WeatherType.values.forEach((element) async {
    weatherImages[element] = await ImageUtils.getImage(WeatherUtils.getWeatherIcon(element));
  });
}